

<<<<<<< HEAD
from PyQt5.QtWidgets import (QApplication,QWidget,QPushButton,
                             QTextEdit,QTextBrowser,QLabel)

from PyQt5.QtGui import QMovie

import  sys

# 导入openai模块
from openai import OpenAI

# 创建OpenAI对象
client = OpenAI(
    api_key='sk-iEj3Ub9cbdWkX6vzgPWmI3hvoaqiMl8bSIDoIs3gsMT27cFM',
    base_url='https://api.chatanywhere.tech'
)

import threading
、





class llmWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.resize(1200,720)

        self.TextBrowser = QTextBrowser(self)
        self.inputEdit = QTextEdit(self)
        self.sendBtn = QPushButton(self)


        self.TextBrowser.resize(760,600)
        self.TextBrowser.move(20,20)
        self.TextBrowser.append("AI:我是一个AI，请输入你的问题")


        self.inputEdit.move(20,650)
        self.inputEdit.resize(650,50)

        self.sendBtn.setText("发送")
        self.sendBtn.move(680,650)
        self.sendBtn.resize(100,50)



        self.sendBtn.clicked.connect(self.sendMessageSlot)

    def sendMessageSlot(self):
        inputMessage= self.inputEdit.toPlainText()
        print(inputMessage)

        self.TextBrowser.append("USER:"+inputMessage+'\n')

        """将信息发送到openai服务器"""
        response = client.chat.completions.create(
            model="gpt-3.5-turbo",  # 指定模型
            messages=[
                {"role": "system", "content": "你是一个有用的助手"},
                {"role": "user", "content": inputMessage},
            ],
            stream=True
        )
        # 获取当前光标
        cursor = self.TextBrowser.textCursor()

        # 移动光标到最后
        cursor.movePosition(cursor.End)
        cursor.insertText("AI:")

        for chunk in response:
            if chunk.choices != []:
                if chunk.choices[0].delta.content != None:
                    llmOut = chunk.choices[0].delta.content
                    cursor.insertText(llmOut)
                    # 立即刷新
                    self.TextBrowser.repaint()
                    # 调回到主线程去刷新ui界面
                    QApplication.processEvents()
                    # self.TextBrowser.append(llmOut)
                    print(chunk.choices[0].delta.content, end='')



if __name__ == '__main__':
    # 创建应用
    app = QApplication(sys.argv)

    # 创建窗口
    window = llmWindow()

    #显示窗口
    window.show()

    # 等待程序退出
    sys.exit(app.exec_())
=======
def main()
    pass
>>>>>>> interface
